home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / nroff~06.zoo / io.c < prev    next >
C/C++ Source or Header  |  1992-07-16  |  5KB  |  292 lines

  1. static char *rcsid_io_c="$Id: io.c,v 1.2 1992/07/16 10:38:32 rosenkra Exp $";
  2.  
  3. /*
  4.  * $Log: io.c,v $
  5.  * Revision 1.2  1992/07/16  10:38:32  rosenkra
  6.  * port to gcc, add tm,ie,el
  7.  *
  8.  */
  9.  
  10. /*
  11.  *    io.c - low level I/O processing portion of nroff word processor
  12.  *
  13.  *    adapted for atariST/TOS by Bill Rosenkranz 11/89
  14.  *    net:    rosenkra@convex.com
  15.  *    CIS:    71460,17
  16.  *    GENIE:    W.ROSENKRANZ
  17.  *
  18.  *    original author:
  19.  *
  20.  *    Stephen L. Browning
  21.  *    5723 North Parker Avenue
  22.  *    Indianapolis, Indiana 46220
  23.  *
  24.  *    history:
  25.  *
  26.  *    - Originally written in BDS C;
  27.  *    - Adapted for standard C by W. N. Paul
  28.  *    - Heavily hacked up to conform to "real" nroff by Bill Rosenkranz
  29.  */
  30.  
  31. #undef NRO_MAIN                    /* extern globals */
  32.  
  33. #include <stdio.h>
  34. #include "nroff.h"
  35.  
  36. /*------------------------------*/
  37. /*    getlin            */
  38. /*------------------------------*/
  39. int getlin (p, in_buf)
  40. char   *p;
  41. FILE   *in_buf;
  42. {
  43.  
  44. /*
  45.  *    retrieve one line of input text
  46.  */
  47.  
  48.     REGISTER char  *q;
  49.     REGISTER int    i;
  50.     int        c;
  51.     int        nreg;
  52.  
  53.     q = p;
  54.     for (i = 0; i < MAXLINE - 1; ++i)
  55.     {
  56.         c = ngetc (in_buf);
  57.         if (c == EOF)
  58.         {
  59.             *q = EOS;
  60.             c  = strlen (p);
  61.             return (c == 0 ? EOF : c);
  62.         }
  63.         *q++ = c;
  64.         if (c == '\n')
  65.             break;
  66.     }
  67.     *q = EOS;
  68.  
  69.     nreg = findreg (".c");
  70.     if (nreg > 0)
  71.         set_ireg (".c", rg[nreg].rval + 1, 0);
  72.  
  73.     return (strlen (p));
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. /*------------------------------*/
  82. /*    ngetc            */
  83. /*------------------------------*/
  84. int ngetc (infp)
  85. FILE   *infp;
  86. {
  87.  
  88. /*
  89.  *    get character from input file or push back buffer
  90.  */
  91.  
  92.     REGISTER int    c;
  93.  
  94.     if (mac.ppb >= &mac.pbb[0])
  95.         c = *mac.ppb--;
  96.     else
  97.     {
  98.         if (infp)
  99.             c = getc (infp);
  100.         else
  101.             c = EOF;
  102.     }
  103.  
  104.     return (c);
  105. }
  106.  
  107.  
  108.  
  109. /*------------------------------*/
  110. /*    pbstr            */
  111. /*------------------------------*/
  112. void pbstr (p)
  113. char   *p;
  114. {
  115.  
  116. /*
  117.  *    Push back string into input stream
  118.  */
  119.  
  120.     REGISTER int    i;
  121.  
  122.     /*
  123.      *   if string is null, we do nothing
  124.      */
  125.     if (p == NULL_CPTR)
  126.         return;
  127.     if (p[0] == EOS)
  128.         return;
  129.     for (i = strlen (p) - 1; i >= 0; --i)
  130.     {
  131.         putbak (p[i]);
  132.     }
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139. /*------------------------------*/
  140. /*    putbak            */
  141. /*------------------------------*/
  142. void putbak (c)
  143. char    c;
  144. {
  145.  
  146. /*
  147.  *    Push character back into input stream. we use the push-back buffer
  148.  *    stored with macros.
  149.  */
  150.  
  151.     if (mac.ppb < &(mac.pbb[0]))
  152.     {
  153.         mac.ppb = &(mac.pbb[0]);
  154.         *mac.ppb = c;
  155.     }
  156.     else
  157.     {
  158.         if (mac.ppb >= &mac.pbb[MAXPBB - 1])
  159.         {
  160.             fprintf (err_stream,
  161.                 "***%s: push back buffer overflow\n", myname);
  162.             err_exit (-1);
  163.         }
  164.         *++(mac.ppb) = c;
  165.     }
  166. }
  167.  
  168.  
  169.  
  170. /*------------------------------*/
  171. /*    prchar            */
  172. /*------------------------------*/
  173. void prchar (c, fp)
  174. char    c;
  175. FILE   *fp;
  176. {
  177.  
  178. /*
  179.  *    print character with test for printer
  180.  */
  181.  
  182. /* this really slows things down. it should be fixed. for now, ignore
  183.    line printer...
  184.  
  185.     if (fp == stdout)
  186.         putc (c, fp);
  187.     else
  188.         putc_lpr (c, fp);
  189. */
  190.     putc (c, fp);
  191. }
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198. /*------------------------------*/
  199. /*    put            */
  200. /*------------------------------*/
  201. void put (p)
  202. REGISTER char  *p;
  203. {
  204.  
  205. /*
  206.  *    put out line with proper spacing and indenting
  207.  */
  208.  
  209.     REGISTER int    j;
  210.     char        os[MAXLINE];
  211.  
  212.     if (pg.lineno == 0 || pg.lineno > pg.bottom)
  213.     {
  214.         phead ();
  215.     }
  216.     if (dc.prflg == TRUE)
  217.     {
  218.         if (!dc.bsflg)
  219.         {
  220.             if (strkovr (p, os) == TRUE)
  221.             {
  222.                 for (j = 0; j < pg.offset; ++j)
  223.                     prchar (' ', out_stream);
  224.                 for (j = 0; j < dc.tival; ++j)
  225.                     prchar (' ', out_stream);
  226.                 putlin (os, out_stream);
  227.             }
  228.         }
  229.         for (j = 0; j < pg.offset; ++j)
  230.             prchar (' ', out_stream);
  231.         for (j = 0; j < dc.tival; ++j)
  232.             prchar (' ', out_stream);
  233.         putlin (p, out_stream);
  234.     }
  235.     dc.tival = dc.inval;
  236.     skip (min (dc.lsval - 1, pg.bottom - pg.lineno));
  237.     pg.lineno = pg.lineno + dc.lsval;
  238.     set_ireg ("ln", pg.lineno, 0);
  239.     if (pg.lineno > pg.bottom)
  240.     {
  241.         pfoot ();
  242.         if (stepping)
  243.             wait_for_char ();
  244.     }
  245. }
  246.  
  247.  
  248.  
  249.  
  250. /*------------------------------*/
  251. /*    putlin            */
  252. /*------------------------------*/
  253. void putlin (p, pbuf)
  254. REGISTER char  *p;
  255. FILE           *pbuf;
  256. {
  257.  
  258. /*
  259.  *    output a null terminated string to the file
  260.  *    specified by pbuf.
  261.  */
  262.  
  263.     while (*p != EOS)
  264.         prchar (*p++, pbuf);
  265. }
  266.  
  267.  
  268.  
  269.  
  270. /*------------------------------*/
  271. /*    putc_lpr        */
  272. /*------------------------------*/
  273. #ifdef GEMDOS
  274. #include <osbind.h>
  275. #endif
  276.  
  277. void putc_lpr (c, fp)
  278. char    c;
  279. FILE   *fp;
  280. {
  281.  
  282. /*
  283.  *    write char to printer
  284.  */
  285.  
  286. #ifdef GEMDOS
  287.     (void) Bconout (0, (int) c & 0x00FF);
  288. #else
  289.     putc (c, fp);
  290. #endif
  291. }
  292.